package com.demo.action;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpRequestHandler;

import com.demo.entity.User;
import com.demo.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
 * Action 层
 * @author Halo.xi
 *
 */
@Component("userAction")
public class UserAction extends ActionSupport implements ModelDriven<User> {
	
	private static final long serialVersionUID = 1L;

	private User user = new User();//一定要先初始化obj对象！
	private String userid;
	


	public String getUserid() {
		return userid;
	}


	public void setUserid(String userid) {
		this.userid = userid;
	}
	private UserService userService;
	  

	@Resource
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	
	/**
	 * login method
	 * agrs:username&password
	 * @return String 
	 */
	public String login() throws Exception {
		
		boolean b = userService.checkNameAndPwd(user.getName(), user.getPassword());
		ActionContext actionContext = ActionContext.getContext();
        Map session = actionContext.getSession(); 
        session.put("userinfo", "1");
		//if(b==true)
			return SUCCESS;
//		else
//			return ERROR;
	}
	public String listUser(){
		//HttpServletRequest request=ServletActionContext.getRequest();
		//id = request.getParameter("id");
		System.out.println("ssssssssss"+userid);
		return SUCCESS;
	}
	/**
	 * struts2 提供的模型驱动类
	 */
	@Override
	public User getModel() {
		System.out.println(user);  
		return user;
	}

}
